package msfgui;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 *
 * @author scriptjunkie
 */
public class ScheduleTaskOptionsDialog extends OptionsDialog {

    /** Creates new form ScheduleTaskOptionsDialog */
    public ScheduleTaskOptionsDialog(JFrame owner) {
		super(owner,"Schedule Task Options",true);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        whenGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        startupButton = new javax.swing.JRadioButton();
        loginButton = new javax.swing.JRadioButton();
        dailyButton = new javax.swing.JRadioButton();
        hourlyButton = new javax.swing.JRadioButton();
        minuteButton = new javax.swing.JRadioButton();
        immediateButton = new javax.swing.JRadioButton();
        uploadField = new javax.swing.JTextField();
        uploadButton = new javax.swing.JButton();
        goButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        commandField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        uploadedArgs = new javax.swing.JTextField();
        remoteScheduleBox = new javax.swing.JCheckBox();
        remoteSystemField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        howManyField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        passwordField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        usernameField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(msfgui.MsfguiApp.class).getContext().getResourceMap(ScheduleTaskOptionsDialog.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        whenGroup.add(startupButton);
        startupButton.setSelected(true);
        startupButton.setText(resourceMap.getString("startupButton.text")); // NOI18N
        startupButton.setName("startupButton"); // NOI18N

        whenGroup.add(loginButton);
        loginButton.setText(resourceMap.getString("loginButton.text")); // NOI18N
        loginButton.setName("loginButton"); // NOI18N

        whenGroup.add(dailyButton);
        dailyButton.setText(resourceMap.getString("dailyButton.text")); // NOI18N
        dailyButton.setName("dailyButton"); // NOI18N

        whenGroup.add(hourlyButton);
        hourlyButton.setText(resourceMap.getString("hourlyButton.text")); // NOI18N
        hourlyButton.setName("hourlyButton"); // NOI18N

        whenGroup.add(minuteButton);
        minuteButton.setText(resourceMap.getString("minuteButton.text")); // NOI18N
        minuteButton.setName("minuteButton"); // NOI18N

        whenGroup.add(immediateButton);
        immediateButton.setText(resourceMap.getString("immediateButton.text")); // NOI18N
        immediateButton.setName("immediateButton"); // NOI18N

        uploadField.setText(resourceMap.getString("uploadField.text")); // NOI18N
        uploadField.setName("uploadField"); // NOI18N

        uploadButton.setText(resourceMap.getString("uploadButton.text")); // NOI18N
        uploadButton.setName("uploadButton"); // NOI18N
        uploadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadButtonActionPerformed(evt);
            }
        });

        goButton.setText(resourceMap.getString("goButton.text")); // NOI18N
        goButton.setName("goButton"); // NOI18N
        goButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                goButtonActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        commandField.setText(resourceMap.getString("commandField.text")); // NOI18N
        commandField.setName("commandField"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        uploadedArgs.setText(resourceMap.getString("uploadedArgs.text")); // NOI18N
        uploadedArgs.setName("uploadedArgs"); // NOI18N

        remoteScheduleBox.setText(resourceMap.getString("remoteScheduleBox.text")); // NOI18N
        remoteScheduleBox.setName("remoteScheduleBox"); // NOI18N

        remoteSystemField.setText(resourceMap.getString("remoteSystemField.text")); // NOI18N
        remoteSystemField.setName("remoteSystemField"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        howManyField.setText(resourceMap.getString("howManyField.text")); // NOI18N
        howManyField.setName("howManyField"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        passwordField.setText(resourceMap.getString("passwordField.text")); // NOI18N
        passwordField.setName("passwordField"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        usernameField.setText(resourceMap.getString("usernameField.text")); // NOI18N
        usernameField.setName("usernameField"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(startupButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(loginButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(dailyButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(hourlyButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(minuteButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(immediateButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(remoteScheduleBox, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(remoteSystemField, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(uploadedArgs, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(uploadButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(uploadField, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(howManyField, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(usernameField, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(passwordField, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(commandField, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(goButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startupButton)
                    .addComponent(uploadField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uploadButton)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(loginButton)
                    .addComponent(jLabel3)
                    .addComponent(uploadedArgs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dailyButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hourlyButton)
                    .addComponent(howManyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(minuteButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(immediateButton)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(remoteScheduleBox)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(remoteSystemField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(usernameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(goButton)
                    .addComponent(commandField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed
		if(MsfguiApp.fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
			uploadField.setText(MsfguiApp.fileChooser.getSelectedFile().getPath());
	}//GEN-LAST:event_uploadButtonActionPerformed

	private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goButtonActionPerformed
		StringBuilder cmd = new StringBuilder("scheduleme ");
		if(loginButton.isSelected())
			cmd.append(" -l");
		else if(immediateButton.isSelected())
			cmd.append(" -i");
		else if(startupButton.isSelected())
			cmd.append(" -s");
		else if(dailyButton.isSelected())
			cmd.append(" -d "+howManyField.getText());
		else if(hourlyButton.isSelected())
			cmd.append(" -hr "+howManyField.getText());
		else if(minuteButton.isSelected())
			cmd.append(" -m "+howManyField.getText());
		if(remoteScheduleBox.isSelected())
			cmd.append(" -r -t "+remoteSystemField.getText());
		if(usernameField.getText().length() > 0)
			cmd.append(" -u "+usernameField.getText()+" -p "+passwordField.getText());
		if(uploadField.getText().length() > 0)
			cmd.append(" -e \"" + MsfguiApp.doubleBackslashes(uploadField.getText()) + "\" -o \""
					+ MsfguiApp.doubleBackslashes(uploadedArgs.getText()) + "\"");
		cmd.append(" -c \"" + MsfguiApp.doubleBackslashes(commandField.getText()) + "\"");
		command = cmd.toString();
		setVisible(false);
	}//GEN-LAST:event_goButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField commandField;
    private javax.swing.JRadioButton dailyButton;
    private javax.swing.JButton goButton;
    private javax.swing.JRadioButton hourlyButton;
    private javax.swing.JTextField howManyField;
    private javax.swing.JRadioButton immediateButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JRadioButton loginButton;
    private javax.swing.JRadioButton minuteButton;
    private javax.swing.JTextField passwordField;
    private javax.swing.JCheckBox remoteScheduleBox;
    private javax.swing.JTextField remoteSystemField;
    private javax.swing.JRadioButton startupButton;
    private javax.swing.JButton uploadButton;
    private javax.swing.JTextField uploadField;
    private javax.swing.JTextField uploadedArgs;
    private javax.swing.JTextField usernameField;
    private javax.swing.ButtonGroup whenGroup;
    // End of variables declaration//GEN-END:variables

}
